package com.algorithm.lesson_06;

import org.junit.Test;

public class LessonTest {
	@Test
	public void testCopyListWithRandom() {
		Node head = null;
		Node resHashMap = null;
		Node resAddCopyNode = null;

		// order: 1->2->3->4->5->6
		head = new Node(1);
		head.next = new Node(2);
		head.next.next = new Node(3);
		head.next.next.next = new Node(4);
		head.next.next.next.next = new Node(5);
		head.next.next.next.next.next = new Node(6);

		// rand:
		head.rand = head.next.next.next.next.next; // 1 -> 6
		head.next.rand = head.next.next.next.next.next; // 2 -> 6
		head.next.next.rand = head.next.next.next.next; // 3 -> 5
		head.next.next.next.rand = head.next.next; // 4 -> 3
		head.next.next.next.next.rand = null; // 5 -> null
		head.next.next.next.next.next.rand = head.next.next.next; // 6 -> 4

		resHashMap = CopyListWithRandom.copyListWithRandByHashMap(head);
		resAddCopyNode = CopyListWithRandom.copyListWithRandomByAddCopyNode(head);

		System.out.println("Source LinkedList");
		CopyListWithRandom.printRandomLinkedList(head);
		System.out.println("======================================");
		System.out.println("Copy Result By HashMap");
		CopyListWithRandom.printRandomLinkedList(resHashMap);
		System.out.println("======================================");
		System.out.println("Copy Result By Add Copy Node");
		CopyListWithRandom.printRandomLinkedList(resAddCopyNode);
	}
}
